08. Extending RANSAC to Planes
Header Text
Extending RANSAC to Planes
Extending RANSAC to Plane
Now that you are getting the hang of RANSACing it, and understanding RANSAC for fitting a line, you can do the same thing for fitting a plane in a 3D point cloud. Your implementation will be used as part of your project, so be sure to complete the implementation in the exercise below!
If you have completed the previous exercise, you can modify your code by using the equation for a plane using three points, and the distance formula for a point to a plane.
Equation of a Plane through Three Points
For
- point1 = (x1, y1, z1)
- point2 = (x2, y2, z2)
- point3 = (x3, y3, z3)
Use point1 as a reference and define two vectors on the plane v1 and v2 as follows:
- Vector v1 travels from point1 to point2 .
- Vector v2 travels from point1 to point3
Find normal vector to the plane by taking cross product of v1 \times v2 :
To simplify notation we can write it in the form
then ,
Distance between point and plane
If the plane is
then given a point (x,y,z) , the distance from the point to the plane is:
When implementing RANSAC, try timing how long it takes to execute and compare its time to PCL's built in RANSAC functions.
Instructions
-
In the workspace below, change line 99, to use
CreateData3D
-
Once Ransac plane fitting is working well, copy the code and extend it to
pointProcessor
,Segment
function
/ Create data
pcl::PointCloud<pcl::PointXYZ>::Ptr cloud = CreateData3D();
-
Modify the
Ransac
function or create a newRansacPlane
function and use the same implementation as before but now with Plane and Point formulas.
Workspace
This section contains either a workspace (it can be a Jupyter Notebook workspace or an online code editor work space, etc.) and it cannot be automatically downloaded to be generated here. Please access the classroom with your account and manually download the workspace to your local machine. Note that for some courses, Udacity upload the workspace files onto https://github.com/udacity , so you may be able to download them there.
Workspace Information:
- Default file path:
- Workspace type: react
- Opened files (when workspace is loaded): n/a